package com.hisense.settings;
import java.util.Locale;

import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Config;
import android.view.ViewGroup;
import android.view.Window;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

import com.android.internal.app.AlertActivity;
import com.android.internal.app.AlertController;
import com.android.settings.R;
public class HisenseLicenseActivity extends AlertActivity{

	private static final String TAG = "HisenseLicenseActivity";
    private static final boolean LOGV = false || Config.LOGV;

    private static final String DEFAULT_LICENSE_PATH = "/system/etc/hisenselegal.html";
    private static final String PROPERTY_LICENSE_PATH = "ro.config.hisense_license_path";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        WebView webView = new WebView(this);
        webView.setHorizontalScrollBarEnabled(false);

        // Begin the loading.  This will be done in a separate thread in WebView.
       // webView.loadDataWithBaseURL(null, data.toString(), "text/html", "utf-8", null);
	   Configuration conf = getResources().getConfiguration();
       Locale defaultLocale = conf.locale;
	   String language = defaultLocale.getLanguage();
	   if(language.equals("fr"))
	   {
			webView.loadUrl("file:///android_asset/hisenselegal-fr.html");
   	   }
	   else if(language.equals("es"))
	   {
			webView.loadUrl("file:///android_asset/hisenselegal-sp.html");
	   }
	   else
   	   {	
	   		webView.loadUrl("file:///android_asset/hisenselegal.html");
	   }
	   
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {
                // Change from 'Loading...' to the real title
                mAlert.setTitle(getString(R.string.settings_hisense_legal_activity_title));
            }
        });

        final AlertController.AlertParams p = mAlertParams;
        p.mTitle = getString(R.string.settings_license_activity_loading);
        p.mView = webView;
        p.mForceInverseBackground = true;
        setupAlert();
        adjustWindowWidth();
        }
    /**
     * Sets the window width for this activity, which requires a slightly
     * larger window.
     */
    private void adjustWindowWidth() {
        Window window = getWindow();
        int width = getResources().getDimensionPixelSize(
                R.dimen.settings_license_activity_width);
        window.setLayout(width, ViewGroup.LayoutParams.WRAP_CONTENT);
    }

    private void showErrorAndFinish() {
        Toast.makeText(this, R.string.settings_license_activity_unavailable, Toast.LENGTH_LONG)
                .show();
        finish();
    }
}
